package org.jspar.expr;

public class RangeExpr extends Expr {

	private int low; // q1
	private int high; // q2
	private int orientation;

	public RangeExpr(int a, int b, int orientation) {
		this.low = Math.min(a, b);
		this.high = Math.max(a, b);
		this.orientation = orientation;
	}

	public int eval() {
		if (low != high) {
			int sum = low + high;
			low = high = sum / 2;
		}
		return low;
	}

	public Expr add(Expr a) {
		int i = a.eval();
		return new RangeExpr(low + i, high + i, orientation);
	}

	public Expr substract(Expr a) {
		int i = a.eval();
		return new RangeExpr(low - i, high - i, orientation);
	}

	public Expr multiply(Expr a) {
		int i = a.eval();
		return new RangeExpr(low * i, high * i, orientation);
	}

	public Expr divide(Expr a)  {
		int i = a.eval();
		return new RangeExpr(low / i, high / i, orientation);
	}

}
